<!-- 车型管理 -->
<template>
  <div class="dashboard-container car-models customer-list-box">
    <div class="win">
      <div class="shang">
        <el-form
          :inline="true"
          :model="query"
          class="demo-form-inline"
          style="backer"
        >
          <el-row>
            <el-col :span="9">
              <el-form-item
                label="车型编号:"
              >
                <el-input
                  v-model="query.id"
                  placeholder="请输入车型编号"
                  style="width:250px"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="应载重量:">
                <el-select
                  v-model="query.allowableLoad"
                  placeholder="活动区域"
                  style="width:210px"
                >
                  <el-option
                    v-for="(item,index) in form.allowableLoadList"
                    :key="index"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="应载体积:">
                <el-select
                  v-model="query.allowableVolume"
                  placeholder="活动区域"
                >
                  <el-option
                    v-for="(item,index) in form.allowableVolumeList"
                    :key="index"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row
            type="flex"
            justify="center"
          >
            <el-col :span="15">
              <el-form-item label="车辆类型:">
                <el-input
                  v-model="query.name"
                  placeholder="请输入车辆类型"
                  style="width:250px"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item>
                <el-button
                  style="background: #e15536; color:#fff; width:85px"
                  @click="getList"
                >搜索</el-button>
                <el-button
                  style="width:85px"
                  @click="clear"
                >重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
      </div>
      <div class="xia">
        <el-row>
          <el-button
            type="danger"
            style="margin-bottom:20px;background: #e15536; color:#fff;"
            @click="addCarType"
          >新增车型</el-button>
        </el-row>

        <el-table
          border
          style="width: 100%"
          :data="list"
        >
          <el-table-column
            label="序号"
            width="100"
          >
            <template v-slot="row">
              <span v-text="row.$index+1"></span>
            </template>
          </el-table-column>
          <el-table-column
            prop="id"
            label="车型编号"
            width="150"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="车辆类型"
            width="150"
          >
          </el-table-column>
          <el-table-column
            prop="num"
            label="车型数量"
            width="100"
          >
          </el-table-column>
          <el-table-column
            prop="allowableLoad"
            label="应载重量（吨）"
            width="150"
          >
          </el-table-column>
          <el-table-column
            prop="allowableVolume"
            label="应载体积（立方米）"
            width="150"
          >
          </el-table-column>
          <el-table-column
            prop="measureLong"
            label="长（米）"
            width="120"
          >
          </el-table-column>
          <el-table-column
            prop="measureWidth"
            label="宽（米）"
            width="120"
          >
          </el-table-column>
          <el-table-column
            prop="measureHigh"
            label="高（米）"
            width="120"
          >
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="120"
          >
            <template v-slot="{row}">
              <el-button
                type="text"
                size="max"
                @click="edit(row.id)"
              >编辑</el-button>
              <span style="color:#ccc">&emsp;|&emsp;</span>
              <el-button
                type="text"
                size="max"
                style="color:#f56c6c"
                @click="delList(row.id)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页器 -->
        <el-pagination
          style="text-align:center"
          :current-page="query.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="query.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="Number(query.counts)"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>

      <carModelsAdd
        ref="addDept"
        :show-dialog.sync="showDialog"
        :edit-id="editId"
        @updataadd="getList"
      ></carModelsAdd>
    </div>

  </div>
</template>
<script>
import { list, del } from '@/api/transit'
import carModelsAdd from './components/car-models-add'
export default {
  components: {
    carModelsAdd
  },
  data() {
    return {
      editId: null,
      showDialog: false,
      form: {
        counts: null,
        id: null,
        name: '',
        allowableLoadList: [
          {
            value: 'RANGE_LEVEL_1',
            name: '<1.8（吨）'
          },
          {
            value: 'RANGE_LEVEL_2',
            name: '1.8-6（吨）'
          },
          {
            value: 'RANGE_LEVEL_3',
            name: '6-14（吨）'
          },
          {
            value: 'RANGE_LEVEL_4',
            name: '14-30（吨）'
          },
          {
            value: 'RANGE_LEVEL_5',
            name: '30-50（吨）'
          },
          {
            value: 'RANGE_LEVEL_6',
            name: '50-100（吨）'
          },
          {
            value: 'RANGE_LEVEL_7',
            name: '100>（吨）'
          }
        ],
        allowableVolumeList: [
          {
            value: 'RANGE_LEVEL_1',
            name: '<3（m³）'
          },
          {
            value: 'RANGE_LEVEL_2',
            name: '3-5（m³）'
          },
          {
            value: 'RANGE_LEVEL_3',
            name: '5-10（m³）'
          },
          {
            value: 'RANGE_LEVEL_4',
            name: '10-15（m³）'
          },
          {
            value: 'RANGE_LEVEL_5',
            name: '15-30（m³）'
          },
          {
            value: 'RANGE_LEVEL_6',
            name: '30-50（m³）'
          },
          {
            value: 'RANGE_LEVEL_7',
            name: '50-80（m³）'
          },
          {
            value: 'RANGE_LEVEL_8',
            name: '80-150（m³）'
          },
          {
            value: 'RANGE_LEVEL_9',
            name: '150>（m³）'
          }
        ]
      },
      list: [],
      query: {
        counts: null,
        id: null,
        name: '',
        page: 1,
        pageSize: 10,
        allowableLoad: '',
        allowableVolume: ''
      }

    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    async getList() {
      const res = await list(this.query)
      this.list = res.data.items
      this.query.counts = res.data.counts
      this.query.page = res.data.page
      this.query.pageSize = res.data.pageSize
    },
    handleSizeChange(val) {
      this.query.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.query.page = val
      this.getList()
    },
    addCarType() {
      this.showDialog = true
    },
    // 删除
    async delList(id) {
      await del(id)
      this.$message.success('删除成功')
      this.getList()
    },
    edit(id) {
      this.editId = id
      this.showDialog = true
      this.$nextTick(() => {
        this.$refs.addDept.detail()
      })
    },
    clear() {
      this.query.id = null
      this.query.name = ''
      this.query.allowableLoad = ''
      this.query.allowableVolume = ''
      this.getList()
    }
  }
}

</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.add-btn{
  margin-bottom: 20px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}

.el-select {
  width: 100%;
}
.shang{
  background-color: #fff;
  margin: 20px;
  padding: 20px 40px;
  height: 145px;
}
.xia{
  background-color: #fff;
  margin: 20px;
  padding: 25px 30px 40px;
}

.car-models /deep/ .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.car-models {
  /deep/ .el-dialog__title {
    width: 73px;
    height: 25px;
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #20232a;
    line-height: 25px;
    letter-spacing: 0px;
  }
  /deep/ .el-dialog__body {
    text-align: center;
    padding: 40px 60px 0 30px;
  }
  .warn-img {
    width: 40px;
  }
  p {
    height: 24px;
    font-size: 16px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: #818693;
    line-height: 24px;
  }
}
</style>
